/*
 * Copyright (c) 2019. J4dream Created.
 */

package com.j4dream.property.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;
import java.util.Arrays;

@Component
@Aspect
@Slf4j
public class UserAspect {

    @Around("execution (* com.j4dream.property.dao.UserDao.*(..))")
    public Object aroundUpdate(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("[环绕前：]");
        Object value = pjp.proceed(); // 执行目标方法
        MethodSignature signature =  (MethodSignature) pjp.getSignature();
        Method method = signature.getMethod();
        String methodName = method.getName();
        String arguments = Arrays.toString(pjp.getArgs());
        String signString = signature.toString();
        log.warn("Method name: " + methodName + ", arguments: "+ arguments + ", signString: " + signString);
        System.out.println("[环绕后：]");
        return value;
    }

//    @After("execution (* com.j4dream.property.dao.UserDao.*(..))")
//    public void
}
